<template>
  <div class="myShare">
    <top></top>
    <div class="index10 food4">
      <div class="index11 food5">
        <div class="index27 food7">
          <el-empty v-if="tableData.length <= 0" style="font-family:'黑体';width:100%" description="暂无数据"></el-empty>
          <div v-if="tableData.length > 0" class="index26 food6" v-for="(item,index) in tableData" :key="index">
            <div class="index28">
              <img :src="item.image.split(',')[0]" @click="toInfo(item.id)">
              <div class="index18">
                <i class="el-icon-star-off"></i> ({{item.favor}}+)
              </div>
              <div class="index19">
                {{index + 1}}
              </div>
            </div>
            <div class="index29">
              <div class="index30">
                <div class="index31">{{item.name}}</div>
                <div class="index32">营业时间:{{item.open}}</div>
                <div class="index25" @click="removeFood">删除</div>
                <div class="index25" style="background-color: green;margin-top:15px" @click="editFood(item.id)">修改</div>
              </div>
            </div>
          </div>
        </div>
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="search.pageSize"
          :current-page="search.pageNumber"
          @current-change="handleCurrentChange"
          :total="total">
        </el-pagination>
      </div>
    </div>
    <bottom></bottom>
  </div>
</template>

<script>
  import {getFoodListPage,removeFoodList} from '../../api/api'
  import top from '@/components/top'
  import bottom from '@/components/bottom'
  export default {
    data() {
      return{
        search: {
          userId: "",
          pageNumber: 1,
          pageSize:12
        },
        total: 0,
        tableData: []
      }
    },
    components: {
        top,
        bottom,
    },
    methods: {
      toInfo(id) {
        this.$router.push("/foodInfo?id=" + id)
      },
      editFood(id) {
        this.$router.push("/editShare?id=" + id)
      },
      removeFood(id) {
        this.$confirm('确定删除这条分享吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.removeFoodList(id)
        }).catch(() => {
                 
        });
      },
      removeFoodList(id) {
        removeFoodList({ids: id}).then(res => {
          if (res.code == 1000) {
            this.$message({
                message: '删除成功',
                type: 'success'
            });
            this.search.pageNumber = 1
            this.getFoodListPage()
          }
        })
      },
      handleCurrentChange(val) {
        this.search.pageNumber = val
        this.getFoodListPage()
      },
      getFoodListPage() {
        getFoodListPage(this.search).then(res => {
          if (res.code == 1000) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      }
    },
    created() {
     
    },
    mounted() {
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      });
      this.getFoodListPage()
    }
 }
</script>

<style scoped>
@import url('../../assets/css/myShare.css');
@import url('../../assets/css/index.css');
</style>